package org.example.studentmanager.service.impl;

import org.example.studentmanager.dao.TeacherDao;
import org.example.studentmanager.dto.StudentScoreDTO;
import org.example.studentmanager.entity.*;
import org.example.studentmanager.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherDao teacherDao;

    // 修改学生成绩
    @Override
    public void updateScore(Score score) {
        score.setUpdate_at(LocalDateTime.now());
        teacherDao.updateScore(score);
    }

    // 录入学生成绩
    @Override
    public void insertScore(Score score) {
        score.setUpdate_at(LocalDateTime.now());
        teacherDao.insertScore(score);
    }
    @Override
    public List<Course> findCourseSelectionsById(Integer id) {
        return teacherDao.findCourseSelectionsById(id);
    }
    @Override
    public List<StudentScoreDTO> findStudentsByCourseId(Integer courseId) {
        return teacherDao.findStudentsByCourseId(courseId);
    }
    /**
     * 通过教师id获取教师信息
     * @param id 教师id
     * @return 教师信息
     * */
    @Override
    public Teacher getTeacherInfoById(Integer id) {
        return teacherDao.getTeacherInfoById(id);
    }

    // 查询所有学生的成绩
    @Override
    public List<Score> findAllScores() {
        return teacherDao.findAllScores();
    }

    // 查询教师选课

    // 教师选课-多选
    @Override
    public void addCourses(TeacherCourseInfo teacherCourseInfo) {
        LocalDateTime now = LocalDateTime.now();  // 获取当前时间
        for (Integer course : teacherCourseInfo.getCourses()) {
            // 添加第三个参数 selection_date
            teacherDao.addCourse(course, teacherCourseInfo.getTeacher_id(), now);
        }
    }
}
